Attribute VB_Name = "modINIHandler"
Option Explicit

Public Declare Function WritePrivateProfileString& Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal filename$)
Public Declare Function GetPrivateProfileString& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal ReturnedString$, ByVal RSSize&, ByVal filename$)

Function FileExists(ByVal filename As String) As Boolean
    On Error GoTo ErrorHandler
    ' get the attributes and ensure that it isn't a directory
    FileExists = (GetAttr(App.Path & "\" & filename) And vbDirectory) = 0
ErrorHandler:
    ' if an error occurs, this function returns False
End Function


Public Sub WriteINI(ByVal INISection As String, ByVal INIKey As String, ByVal INIValue As String, ByVal INIFile As String)
    Call WritePrivateProfileString(INISection, INIKey, INIValue, INIFile)
End Sub

Public Function ReadINI(INISection As String, INIKey As String, ByVal INIFile As String) As String
    Dim StringBuffer As String
    Dim StringBufferSize As Long

    StringBuffer = Space$(255)
    StringBufferSize = Len(StringBuffer)

    StringBufferSize = GetPrivateProfileString(INISection, INIKey, vbNullString, StringBuffer, StringBufferSize, INIFile)

    If StringBufferSize > 0 Then
        ReadINI = Left$(StringBuffer, StringBufferSize)
    Else
        ReadINI = vbNullString
    End If
End Function

'Deletes Key and it's value
Public Sub DeleteINIKey(sSection As String, sKeyName As String, sIniFile As String)
    'http://vbnet.mvps.org/index.html?code/file/pprofilebasic.htm
   Call WritePrivateProfileString(sSection, sKeyName, vbNullString, sIniFile)

End Sub

'Deletes Section in the INI file
Public Sub DeleteINISection(sSection As String, sIniFile As String)
   'http://vbnet.mvps.org/index.html?code/file/pprofilebasic.htm
   Call WritePrivateProfileString(sSection, vbNullString, vbNullString, sIniFile)

End Sub

